package MyArrays;

import java.util.Arrays;
import java.util.Comparator;

public class demo2 {
    public static void main(String[] args) {
     GirlFriend g1 = new GirlFriend("xiaoshishi",18,1.67);
     GirlFriend g2 = new GirlFriend("xiaodandan",19,1.72);
     GirlFriend g3 = new GirlFriend("xiaohuahua",19,1.78);
     GirlFriend []arr = {g1,g2,g3};
        Arrays.sort(arr, new Comparator<GirlFriend>() {
            @Override
            public int compare(GirlFriend o1, GirlFriend o2) {
                double temp = o1.getAge() - o2.getAge();
                temp = temp == 0 ? o2.getHeight() - o1.getHeight() : temp;
                temp = temp == 0 ? o1.getName().compareTo(o2.getName()) : temp;
                if(temp > 0){
                    return 1;
                } else if (temp < 0) {
                    return -1;
                }else{
                    return 0;
                }
            }
        });
        System.out.println(Arrays.toString(arr));
    }
}
class GirlFriend {
    private String name;
    private int age;
    private double height;

    public GirlFriend() {
    }

    public GirlFriend(String name, int age, double height) {
        this.name = name;
        this.age = age;
        this.height = height;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取
     * @return height
     */
    public double getHeight() {
        return height;
    }

    /**
     * 设置
     * @param height
     */
    public void setHeight(double height) {
        this.height = height;
    }

    public String toString() {
        return "GirlFriend{name = " + name + ", age = " + age + ", height = " + height + "}";
    }
}
